import flask
from datetime import datetime

app = flask.Flask(__name__)

@app.route('/')
def demo():
  return 'hello'

# http://127.0.0.1:3000/demos/1111
@app.route('/demos/<id>')
def demos(id):
  return id

# http://127.0.0.1:3000/bookList?page=2
@app.route('/bookList')
def bookList():
  page = flask.request.args.get('page',default=1)
  return f'获取到第{page}页'

#post入参访问：from-data（k-v）格式参数 http://127.0.0.1:3000/login
@app.route('/login',methods=['post'])
def login():
  usrname = flask.request.values.get('usrname')
  pwd = flask.request.values.get('pwd')
  return f'用户名是{usrname},密码是{pwd}'


# 模板渲染
@app.route('/index/<id>')
def index(id):
  info = {
    'name':'崔城',
    'age':'12'
  }
  return flask.render_template('index.html', id = id,info = info)

@app.route('/konhzhi')
def konhzhi():
  age = 19
  books = ['水浒传','西游记','三国演义']
  return flask.render_template('konhzhi.html', age = age ,books = books)


if __name__ == '__main__':
  app.run(debug=True,port=3000)